var API = API || {};

API.Colorbox = {
    offsetX: $(window).innerWidth() - 100 + "px",
    offsetY: $(window).innerHeight() - 100 + "px",
    HTML: $("#google_box").html()

};

$(document).ready(function() {

    // Defining variables
    var gh_obj = '.GH';
    var google_map_component = 'google_map';

    if (typeof m !== 'undefined' && m !== '' && m.length >= 1) {

        $("#google_box").remove();
        $(".show_map").colorbox({
            html: "<div id='google_box'>" + API.Colorbox.HTML + "</div>",
            scrolling: false,
            width: '93%',
            height: '93%',
            onComplete: function() {

                $('#google_box').show();
                gmpapH = $('#cboxLoadedContent').innerHeight();
                $("#google_map").css('height', gmpapH);
                $("#google-list").css('height', gmpapH);

                var data_id = $(this).attr('data-id');

                if (typeof data_id === 'undefined') {
                    data_id = 'ALL'
                }

                var gm = new API.Google.MapsManager(m, gh_obj, google_map_component);
                gm.Init(data_id);

            }
        });

    } else {
        $(".show_map").on('click', function() {
            alert('Nothing to show!')
        });
    }

//    $('#cboxOverlay').on('mousewheel', function(e, delta) {
//        // Restricts mouse scrolling to the scrolling range of this element.
//        if (
//                this.scrollTop < 1 && delta > 0 ||
//                (this.clientHeight + this.scrollTop) === this.scrollHeight && delta < 0
//                ) {
//            e.preventDefault();
//        }
//    });
//    $('#colorbox').on('mousewheel', function(e, delta) {
//        // Restricts mouse scrolling to the scrolling range of this element.
//        if (
//                this.scrollTop < 1 && delta > 0 ||
//                (this.clientHeight + this.scrollTop) === this.scrollHeight && delta < 0
//                ) {
//            e.preventDefault();
//        }
//    });

    if (typeof m !== 'undefined' && m !== '' && m.length >= 1 && API.Data.method == 'accommodation') {

        $('#do_google_map').on('click', function() {

            data_id = $('#show_on_map').attr('data-id');

            var gm = new API.Google.MapsManager(m, gh_obj, google_map_component);
            gm.Init(data_id);

            return false;
        })
        $('.show_map_inline').on('click', function() {
            $.scrollTo('#tabvanilla', 500);
            $('#do_google_map').trigger('click');

            return false;
        });
    } else {
        $('#show_on_map').on('click', function() {

            alert('Nothing to show!')

        });
    }

});